<?php

load_theme_textdomain('igoogler', get_template_directory() . '/languages');

function igoogler_admin_panel() {
	global $themename;
	global $shortname;
	global $options;
	if ( isset( $_GET['page'] ) && $_GET['page'] == basename(__FILE__) ) {
		if ( isset($_REQUEST['action']) && 'save' == $_REQUEST['action'] ) {
			foreach ($options as $value) {
				if( isset( $_REQUEST[ $value['id'] ] ) ) {
					update_option( $shortname.$value['id'], $_REQUEST[ $value['id'] ] );
					update_option( $shortname.'init', true);
				} else {
					update_option( $shortname.$value['id'], NULL );
				}
			}
			header("Location: themes.php?page=func_panel.php&saved=true");
			die;
		} else if( isset($_REQUEST['action']) && 'reset' == $_REQUEST['action'] ) {
			foreach ($options as $value) {
				update_option( $shortname.$value['id'], $value['std'] );
			}
			header("Location: themes.php?page=func_panel.php&reset=true");
			die;
		}
	}
	add_theme_page($themename." Options", __('iGoogler Settings', 'igoogler'), 'edit_themes', basename(__FILE__), 'igoogler_admin');
}
function igoogler_admin() {
	global $themename, $shortname, $options;
	if ( isset( $_REQUEST['saved'] ) ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.__('Settings Saved', 'igoogler').'</strong></p></div>';
	if ( isset( $_REQUEST['reset'] ) ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.__('Settings Reseted', 'igoogler').'</strong></p></div>';
	?>

<div class="wrap">
	<div id="icon-options-general" class="icon32">
		<br>
	</div>
	<h2><?php _e('iGoogler Theme Settings', 'igoogler')?></h2>
	<form method="post">
		<input type="hidden" name="action" value="save" />
		<h3><?php _e('Common Settings', 'igoogler')?></h3>
		<table class="form-table">
			<tbody>
				<?php foreach ($options as $value):?>
				<tr>
					<th scope="row"><?php if($value['type'] == "h3"): ?>
						<h3>
							<?php _e($value['title'],'igoogler');?>
						</h3> <?php else:?> <?php echo _e($value['title'], 'igoogler')?> <?php endif;?></th>
					<td><?php if($value['type'] == "h3"): ?> <?php elseif ($value['type'] == "checkbox"):?>
						<input type="<?php echo $value['type']?>"
						name="<?php echo $value['id'];?>" id="<?php echo $value['id']?>"
						<?php if(get_option($shortname.$value['id'],$value['std']))echo 'checked="true"';?> />
						<?php elseif ($value['type'] == "textarea"):?> <textarea
							name="<?php echo $value['id'];?>" id="<?php echo $value['id'];?>"
							class="large-text code"><?php echo stripslashes(get_option($shortname.$value['id'],$value['std']));?></textarea> <br /> <?php else:?> <input
						type="<?php echo $value['type']?>"
						name="<?php echo $value['id'];?>" id="<?php echo $value['id']?>"
						value="<?php echo get_option($shortname.$value['id'],$value['std']);?>" />
						<?php endif;?> <span class="description"><?php _e($value['description'], 'igoogler')?>
					</span></td>
				</tr>
				<?php endforeach;?>
			</tbody>
		</table>
		<p class="submit">
			<input type="submit" class="button-primary" value="<?php _e('Save')?>" />
		</p>
	</form>
	<h3>iGoogler Updates</h3>
	<div class="rss-widget" style="float:left;padding:10px;border:1px solid #CCC;border-radius:5px;height:130px;margin-right:15px;">
	<?php  
	     wp_widget_rss_output(array(  
		  'url' => 'http://igoogler.us/feed',  //put your feed URL here  
		  'title' => 'iGoogler News',  
		  'items' => 4, //how many posts to show  
		  'show_summary' => 0,  
		  'show_author' => 0,  
		  'show_date' => 1  
	     )); 
	?>
	</div>
	<div class="rss-widget" style="float:left;padding:10px;border:1px solid #CCC;border-radius:5px;height:130px;margin-right:15px;">
	<?php  
	     wp_widget_rss_output(array(  
		  'url' => 'http://code.google.com/feeds/p/igoogler/downloads/basic',  //put your feed URL here  
		  'title' => 'iGoogler News',  
		  'items' => 4, //how many posts to show  
		  'show_summary' => 0,  
		  'show_author' => 0,  
		  'show_date' => 1  
	     )); 
	?>
	</div>
	<div style="clear:both;"></div>
</div>
<?php
}
add_action('admin_menu', 'igoogler_admin_panel');
?>
